package com.medusa.aps.business.modules.basic.mp.entity;

import cn.hutool.core.annotation.Alias;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.*;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.validator.constraints.Length;

import java.math.BigDecimal;

@Getter
@Setter
public class SupplierMaterialDTO {

    /**
     * 供应商id
     */
    @Schema(description = "供应商id")
    private Long supplierId;

    /**
     * 物料id
     */
    @Schema(description = "物料id")
    private Long materialId;

    /**
     * 物料编码
     */
    @Alias("物料编码")
    @Schema(description = "物料编码")
    @NotBlank(message = "物料编码不能为空")
    private String materialCode;

    /**
     * 物料名称
     */
    @Alias("物料名称")
    @Schema(description = "物料名称")
    @Length(max = 50, message = "物料名称长度不能超过50")
    @NotBlank(message = "物料名称不能为空")
    private String materialName;

    /**
     * 成品率
     */
    @Schema(description = "成品率")
    @NotNull(message = "成品率不能为空")
    @DecimalMax(value = "100.00", message = "成品率不能大于100")
    @DecimalMin(value = "1.00", message = "成品率不能小于1")
    @Digits(integer = 3, fraction = 2, message = "成品率格式不正确")
    private BigDecimal finishedProductRate;

    /**
     * 准交率
     */
    @Schema(description = "准交率")
    @NotNull(message = "准交率不能为空")
    @DecimalMax(value = "100.00", message = "准交率不能大于100")
    @DecimalMin(value = "1.00", message = "准交率不能小于1")
    @Digits(integer = 3, fraction = 2, message = "准交率格式不正确")
    private BigDecimal quasiDeliveryRate;

    public SupplierMaterial newSupplierMaterial(Long supplierId) {
        return new SupplierMaterial()
                .setSupplierId(supplierId)
                .setMaterialId(materialId)
                .setMaterialCode(materialCode)
                .setMaterialName(materialName)
                .setFinishedProductRate(finishedProductRate)
                .setQuasiDeliveryRate(quasiDeliveryRate);
    }
}
